package com.zy.composeworld.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.zy.composeworld.base.adapter.BaseActivityAdapter
import com.zy.composeworld.base.bean.BaseMenuBean
import com.zy.composeworld.databinding.FragmentListBaseBinding
import com.zy.composeworld.utils.ZLog
import java.util.ArrayList

abstract class BaseSimpleListFragment : BaseFragment() {

    protected lateinit var binding: FragmentListBaseBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ZLog.d("BaseSimpleListFragment", "onCreate:$this")
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        //fragment_list_base
        binding = FragmentListBaseBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val list: ArrayList<BaseMenuBean> = ArrayList()
        list.initList()
        val adapter = BaseActivityAdapter(list)
        binding.baseRv.adapter = adapter

        binding.baseRv.layoutManager = if (linear())
            LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
        else
            GridLayoutManager(requireContext(), gridSize())
    }

    open fun linear() = false
    open fun gridSize() = 1

    open fun ArrayList<BaseMenuBean>.initList() {}


    open fun getCurId(): String {
        return this::class.java.simpleName + "[" + this.hashCode() + "]"
    }
}